package log4j;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class Log {

	private static Logger log = Logger.getLogger(Thread.currentThread().getStackTrace()[0].getClassName());
	private static final String FQCN = Thread.currentThread().getStackTrace()[0].getClassName();

	public static void Init() {
		DOMConfigurator.configureAndWatch("logj.xml");
	}

	public static void Init(String Filename) {
		String endStr1 = ".properties";
		if (Filename.endsWith(endStr1)) {
			PropertyConfigurator.configure(Filename);
		} else {
			DOMConfigurator.configureAndWatch(Filename);
		}
	}

	public static void Debug(Object message) {
		log.log(FQCN, Level.DEBUG, message, null);
	}

	public static void Debug(Object message, Throwable e) {
		log.log(FQCN, Level.DEBUG, message, e);
	}

	public static void Info(Object message) {
		log.log(FQCN, Level.INFO, message, null);
	}

	public static void Info(Object message, Throwable e) {
		log.log(FQCN, Level.INFO, message, e);
	}

	public static void Warn(Object message) {
		log.log(FQCN, Level.WARN, message, null);
	}

	public static void Warn(Object message, Throwable e) {
		log.log(FQCN, Level.WARN, message, e);
	}

	public static void Error(Object message) {
		log.log(FQCN, Level.ERROR, message, null);
	}

	public static void Error(Object message, Throwable e) {
		log.log(FQCN, Level.ERROR, message, e);
	}

	public static void Fatal(Object message) {
		log.log(FQCN, Level.FATAL, message, null);
	}

	public static void Fatal(Object message, Throwable e) {
		log.log(FQCN, Level.FATAL, message, e);
	}

	public static boolean IsDebug() {
		return log.isDebugEnabled();
	}

	public static boolean IsInfo() {
		return log.isInfoEnabled();
	}

	public static boolean IsWarn() {
		return log.isEnabledFor(Level.WARN);
	}

	public static boolean IsError() {
		return log.isEnabledFor(Level.ERROR);
	}

	public static boolean IsFatal() {
		return log.isEnabledFor(Level.FATAL);
	}

	public static void setLevel(String level) {
		log.setLevel(Level.toLevel(level));
	}

	public static String getLevel() {
		if (log.isDebugEnabled()) {
			return "DEBUG";
		} else if (log.isInfoEnabled()) {
			return "INFO";
		} else if (log.isEnabledFor(Level.WARN)) {
			return "WARN";
		} else if (log.isEnabledFor(Level.ERROR)) {
			return "ERROR";
		} else if (log.isEnabledFor(Level.FATAL)) {
			return "FATAL";
		}
		return null;
	}
}
